package log

import "fmt"

//输出到终端是没有行号的
func DebugNL(v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}
	if logLevel <= debug_level {
		logStderr("",debug_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[debug_level], "[DEBUG]"), v))
		}
	}
}
func InfoNL(v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}
	if logLevel <= info_level {
		logStderr("",info_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[info_level], "[INFO]"), v))
		}
	}
}


func WarnNL(v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}

	if logLevel <= warn_level {
		logStderr("",warn_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[warn_level], "[WARN]"), v))
		}
	}
}

func ErrorNL(v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}
	if logLevel <= error_level {
		logStderr("",error_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[error_level], "[ERROR]"), v))
		}
	}
}

func FatalNL(v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}
	if logLevel <= fatal_level {
		logStderr("",fatal_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[fatal_level], "[FATAL]"), v))
		}
	}
}

func DebugfNL(format string, v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}

	if logLevel <= debug_level {
		logStderr(format,debug_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[debug_level], "[DEBUG]"), fmt.Sprintf(format, v...)))
		}
	}
}

func InfofNL(format string, v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}
	if logLevel <= info_level {
		logStderr(format,info_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[info_level], "[INFO]"), fmt.Sprintf(format, v...)))
		}
	}
}

func WarnfNL(format string, v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}

	if logLevel <= warn_level {
		logStderr(format,warn_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[warn_level], "[WARN]"), fmt.Sprintf(format, v...)))
		}
	}
}

func ErrorfNL(format string, v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}

	if logLevel <= error_level {
		logStderr(format,error_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[error_level], "[ERROR]"), fmt.Sprintf(format, v...)))
		}
	}
}

func FatalfNL(format string, v ...interface{}) {
	if dailyRolling {
		fileCheck()
	}
	defer catchError()
	if logObj != nil {
		logObj.mu.RLock()
		defer logObj.mu.RUnlock()
	}

	if logLevel <= fatal_level {
		logStderr(format,fatal_level,false,v...)
		if gOpt.logtostderr == true{
			return
		}
		if logObj != nil {
			logObj.lg.Output(2, fmt.Sprintln(color(levelColor[fatal_level], "[FATAL]"), fmt.Sprintf(format, v...)))
		}
	}
}
